import { serviceCreate, cancelSource } from '../utils/request'
import { merge } from 'axios/lib/utils'
const http = serviceCreate({
  // baseURL: '/dv',
  // 表单提交
  emulateJSON: true
})
// @config {headers, emulateJSON, loading, msg, errMsg, disableInterceptor}
const methods = {
    // 获取中断axios请求所需要的 取消的数据源 
    getCancelSource() {
        return cancelSource
    },
    // 获取默认搜索
    getDefault (params, config) {
        return http.get('/search/getDefaultKey', merge(config, { params }))
    },
    // 获取热门搜索
    getHotSearch (params, config) {
        return http.get('/search/getHotKey', merge(config, { params }))
    },
    // 获取搜索建议
    getSuggest (params, config) {
        params = merge({
            func: 'suggest',
            suggest_type: 'accurate',
            sub_type: 'tag',
            main_ver: 'v1',
            highlight: '',
            bangumi_acc_num: 3,
            special_acc_num: 0,
            upuser_acc_num: 0,
            tag_num: 10,
            // 搜索关键字
            term: '',
            rnd: Math.random()
        }, params || {})
        return http.get('/search/getSuggest', merge(config, { params }))
    },
    // 获取搜索结果
    // url: /search/getResult | /search/byKeyword
    getSearchResult (url, params, config) {
        return http.get(url, merge(config, { params }))
    }
}

export default methods
